﻿<%@ Page Title="" Language="C#" MasterPageFile="~/SiteJN.Master" AutoEventWireup="true" CodeBehind="default.aspx.cs" Inherits="jnagr.Web.ground._default" %>

<%@ Register Src="~/Controls/checkright.ascx" TagPrefix="uc1" TagName="checkright" %>
<%@ Register Src="~/Controls/copyright.ascx" TagPrefix="uc1" TagName="copyright" %>
<%@ Register Src="~/Controls/ground.ascx" TagPrefix="uc1" TagName="ground" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <style>
        .fite {
            float: left;
            margin: 2px;
        }
    </style>
   
    <script type="text/javascript">
        var sprovince = "";
        var scity = "";
        var scounty = "";
        var areas = "";
        var se = "";
        var sebm = "";
        var getdata = "";
        var getdata1 = "";
        var curindex = 0;
        var level;
        var markerClusterer;
        var markers = [];
        var devid;
        var XQHID = "土壤温度1,土壤温度2,土壤温度3,土壤温度4,土壤温度5,土壤湿度1,土壤湿度2,土壤湿度3,土壤湿度4,土壤湿度5";//气候参数
        var wchartInstance;
        var chs = "";
        var pt;
        var uid = "";
        var map;
        var data_info;
        var opts;
        var dtOpstart;
        var dtOpend;
        var ch = new Array("", "", "", "");
        var myrz = "";
        var mycs = "";
        var mywn = "";
        var mytz = "";
        var lvalue = 0;
        var hvalue = 0;
        var gx = 0;
        var gpic = "";
        var gdate = "";
        var hzdata = "";
        var $li="";
        $(function () {

            $("#tab").tabs({
                onSelect: function (title, index) {
                    if (index == '2') {
                        InitHZ();
                    }

                }
            });
            $.ajax({
                type: "post",
                dataType: "json",
                url: "../admin/getinfo.ashx?action=level",
                success: function aa(data) {
                    sprovince = data[0].province;
                    scity = data[0].city;
                    scounty = data[0].county;
                    InitTree();
                    InitMap();
                }
            });
        });
        function InitHZ() {
            $('#hzgrid').datagrid({
                title: '墒情', //表格标题
                url: '../devinfo/GetStatus.ashx', //请求数据的页面
                sortName: 'DevID', //排序字段
                idField: 'KeyId', //标识字段,主键
                iconCls: '', //标题左边的图标
                width: '100%', //宽度
                height: 400,
                nowrap: false, //是否换行，True 就会把数据显示在一行里
                striped: true, //True 奇偶行使用不同背景色
                collapsible: false, //可折叠
                sortOrder: 'desc', //排序类型
                remoteSort: true, //定义是否从服务器给数据排序
                fitColumns: true,
                singleSelect:false,
                method: 'post',
                columns: [[
                    { field: 'ckb', checkbox: true },
                    { title: '设备名', field: 'devname', width: 150 },
                    { title: '设备ID', field: 'DevID', width: 150 },
                    { title: '土壤温度1', field: '土壤温度1', width: 60 },
                    { title: '土壤温度2', field: '土壤温度2', width: 60 },
                    { title: '土壤温度3', field: '土壤温度3', width: 60 },
                    { title: '土壤温度4', field: '土壤温度4', width: 60 },
                    { title: '土壤温度5', field: '土壤温度5', width: 60 },
                    { title: '土壤湿度1', field: '土壤湿度1', width: 60 },
                    { title: '土壤湿度2', field: '土壤湿度2', width: 60 },
                    { title: '土壤湿度3', field: '土壤湿度3', width: 60 },
                    { title: '土壤湿度4', field: '土壤湿度4', width: 60 },
                    { title: '土壤湿度5', field: '土壤湿度5', width: 60 }
                ]
                ],
                onLoadSuccess: function (data) {
                    hzdata = data;
                },
                queryParams: { "action": "HZTSQ", "StartTime": $("#txtstart").datebox("getValue"), "EndTime": $("#txtend").datebox("getValue"), "sebm": sebm },
                toolbar: "#hztoolbar",
                pagination: true, //是否开启分页
                pageNumber: 1, //默认索引页
                pageSize: 20, //默认一页数据条数
                rownumbers: true

            });
        }
        function InitMapmark() {
            $('#win').datagrid({
                //title: '测报点列表', //表格标题
                url: '../devinfo/GetDev.ashx', //请求数据的页面
                sortName: 'mname', //排序字段
                idField: 'mid', //标识字段,主键
                iconCls: '', //标题左边的图标
                width: '95%', //宽度
                height: '95%', //高度
                nowrap: false, //是否换行，True 就会把数据显示在一行里
                striped: true, //True 奇偶行使用不同背景色
                collapsible: false, //可折叠
                sortOrder: 'desc', //排序类型
                remoteSort: true, //定义是否从服务器给数据排序
                fitColumns: true,
                singleSelect: true,
                method: 'post',
                columns: [[
	                { title: '测报站名', field: 'mname', width: 80, sortable: true }
                ]],
                toolbar: "#tab_toolbar",
                queryParams: { "action": "querydev", "dtype": "TSQ" },
                pageNumber: 1, //默认索引页
                pageSize: 500, //默认一页数据条数
                rownumbers: true, //行号
                pageList: [10, 20, 50, 200, 500],
                pagination: false, //是否开启分页                
                onLoadSuccess: function (data) {
                    data_info = [];
                    getdata = data;
                    map.clearOverlays();
                    $.each(data.rows, function (k, v) {
                        data_info.push({ "lng": v["mjd"], "lat": v["mwd"], "mlevel": v["DevType"], "mname": v["devname"], "madd": v["DevLocation"], "rz": v["chn0"], "cs": v["chn1"], "wn": v["chn2"], "devid": v["DevID"],"tz": v["XQHID"] });
                    });
                    var mlevel;
                    var marker;
                    var ptt = "";
                    if (markers.length > 0) {
                        if (markerClusterer != null) {
                            markerClusterer.removeMarkers(markers);
                            markerClusterer = null;
                        }
                        markers = [];
                    }
                    for (var i = 0; i < data_info.length; i++) {
                        mlevel = data_info[i].mlevel;
                        ptt = new BMap.Point(data_info[i].lng, data_info[i].lat);
                        if (mlevel == 'CBD')
                            marker = new BMap.Marker(ptt, { icon: icon4 });
                        else if (mlevel == 'YBQ')
                            marker = new BMap.Marker(ptt, { icon: icon3 });
                        else if (mlevel == 'XQH')
                            marker = new BMap.Marker(ptt, { icon: icon2 });
                        else
                            marker = new BMap.Marker(ptt, { icon: icon1 });

                        var did = data_info[i].devid;
                        var rz = data_info[i].rz;
                        var cs = data_info[i].cs;
                        var wn = data_info[i].wn;
                        var tz = data_info[i].tz;
                        map.addOverlay(marker);
                        label = new BMap.Label(data_info[i].mname, { offset: new BMap.Size(20, -10) });
                        marker.setLabel(label);
                        markers.push(marker);
                        addClickHandler(did, rz, cs, wn,tz, marker);
                    }
                    if (markers.length > 0)
                        markerClusterer = new BMapLib.MarkerClusterer(map, { markers: markers });//对地图扩大缩小后会都所有的点全显示出来。
                    if (scounty != "")
                        map.centerAndZoom(scounty, 12);
                    else if (scity != "")
                        map.centerAndZoom(scity, 10);
                    else if (sprovince != "")
                        map.centerAndZoom(sprovince, 8);
                    else
                        map.centerAndZoom("西安", 5);
                    if (areas != "")
                        getBoundary(areas);
                    renderstation();
                }
            });
        }

        function addClickHandler(did, rz, cs, wn,tz, marker) {
            marker.addEventListener("click", function (e) {
                showawsinfectInfo(did, rz, cs, wn,tz);
            }
            );
        }
        function InitTree() {
            $('#pt').tree({
                width: '100%', //宽度 
                lines: true,
                //data: provincetree,   
                url: '../areainfo/GetArea.ashx', //请求数据的页面 
                method: 'post',
                queryParams: { "action": "querymyareauser" },
                onBeforeExpand: function (node) {
                    $("#pt").tree("options").queryParams = { "action": "queryyb" };
                    $('#pt').tree('options').url = "../areainfo/GetArea.ashx?pid=" + node.id;
                },
                onClick: function (node) {
                    if (node.text != "") {
                        sebm = node.bm;
                        //获取地区全称
                        if (sebm == "0")
                            areas = "";
                        else if (sebm.length == 6 && sebm.indexOf("0000")) {
                            areas = node.text;
                        }
                        else {
                            var result = $.ajax({
                                url: "../areainfo/GetArea.ashx?action=queryarea",
                                type: 'post',
                                dataType: 'json',
                                async: false,
                                cache: false
                            }).responseText;
                            areas = result;
                        }
                        reloadgridTree();
                    }
                },
                onLoadSuccess: function (node, param) {
                }
            });
        }
        function showawsinfectInfo(did, rz, cs, wn,tz) {
            devid = did;
            myrz = rz.split(",");
            mycs = cs.split(",");
            mywn = wn.split(",");
            mytz = tz.split(",");
            //var wh = $(window).height() - 100;
            //var ww = $(window).width() - 300;
           
            addTab(devid,'mywin.html');            
            //$('#mywin').window({
            //    width: ww,
            //    height: wh,
            //    modal: true,
            //    title: '墒情',
            //    closed: false
            //}).window('center');
            
        }

        function InitGird() {
            var h = $("#my1").height();
            var w = $("#my1").width();
            chs = XQHID.split(',');
            $('#mtgrid').datagrid({
                title: '墒情历史信息', //表格标题
                url: '../devinfo/GetStatus.ashx', //请求数据的页面
                sortName: 'datetime', //排序字段
                idField: 'ID', //标识字段,主键
                iconCls: '', //标题左边的图标
                width: w, //宽度
                height: h,
                nowrap: false, //是否换行，True 就会把数据显示在一行里
                striped: true, //True 奇偶行使用不同背景色
                collapsible: false, //可折叠
                sortOrder: 'desc', //排序类型
                remoteSort: true, //定义是否从服务器给数据排序
                fitColumns: true,
                singleSelect: false,
                method: 'post',
                columns: [[
                    { title: '土壤温度1', field: '土壤温度1', width: 60 },
                    { title: '土壤温度2', field: '土壤温度2', width: 60 },
                    { title: '土壤温度3', field: '土壤温度3', width: 60 },
                    { title: '土壤温度4', field: '土壤温度4', width: 60 },
                    { title: '土壤温度5', field: '土壤温度5', width: 60 },
                    { title: '土壤湿度1', field: '土壤湿度1', width: 60 },
                    { title: '土壤湿度2', field: '土壤湿度2', width: 60 },
                    { title: '土壤湿度3', field: '土壤湿度3', width: 60 },
                    { title: '土壤湿度4', field: '土壤湿度4', width: 60 },
                    { title: '土壤湿度5', field: '土壤湿度5', width: 60 },
                    {
                        title: '监测时间', field: 'datetime', width: 150, formatter: function (value, row, index) {
                            if (value != "") {

                                if (value.indexOf("-") != -1)
                                    value = value.replace(/-/g, "/")
                                return new Date(value).pattern("yyyy年M月d日");
                            }
                        }
                    }
                ]
                ],
                onLoadSuccess: function (data) {
                    getdata1 = data;
                    //初始化第一条数据
                    changechart();
                    Initonegrid(0);
                },
                toolbar: "#tab_toolbars",
                queryParams: { "action": "TSQ", "devID": devid, "StartTime": $("#StartTime").datebox("getValue"), "EndTime": $("#EndTime").datebox("getValue") },
                pagination: true, //是否开启分页
                pageNumber: 1, //默认索引页
                pageSize: 20, //默认一页数据条数
                pageList: [10, 20, 40, 50, 10000],
                rownumbers: true
            });


        }
        function changechart() {
            WChartJS.init(chs);
            var md;
            var t1 = "";
            $.each(getdata1.rows, function (k, v) {
                md = v["datetime"];
                md = md.replace(/-/g, "/");
                md = Date.parse(md);
                t1 = md + "," + t1;

            });
            t1 = t1 = "[" + t1 + "]";
            wchartInstance.xAxis[0].setCategories(eval(t1));
            var j = 0;
            for (var i = 0; i < chs.length; i++) {
                t1 = "";
                $.each(getdata1.rows, function (k, v) {
                    md = v["datetime"];
                    t1 = "[" + v[chs[i]] + "]," + t1;

                });
                t1 = "[" + t1 + "]";
                wchartInstance.series[j].setData(eval(t1));
                j++;
            }
            sercount = j;
            for (var i = 0; i < j; i++) {
                if (i != 0)
                    wchartInstance.series[i].hide();
            }
        }
        function getQueryParams(queryParams) {
            var StartTime = $("#StartTime").datebox("getValue");
            var EndTime = $("#EndTime").datebox("getValue");

            queryParams.StartTime = StartTime;
            queryParams.EndTime = EndTime;
            return queryParams;

        }
        //增加查询参数，重新加载表格  
        function reloadgrid() {
            var queryParams = $('#mtgrid').datagrid('options').queryParams;
            getQueryParams(queryParams);
            $('#mtgrid').datagrid('options').queryParams = queryParams;
            $("#mtgrid").datagrid('reload');

        }
        var wchartInstance;
        var WChartJS = {
            init: function (chs) {
                var s = "[";
                $.each(chs, function () {
                    s = s + "{name:'" + this + "',data:[]},";
                });
                s = s.substr(0, s.length - 1);
                s = s + "]";
                wchartInstance = new Highcharts.Chart({
                    chart: {
                        renderTo: 'chartArea',
                        type: 'line'
                    },
                    credits: {
                        enabled: false
                    },
                    exporting: {
                        enabled: true
                    },
                    title: {
                        text: '',
                        x: -20 //center
                    },
                    xAxis: {
                        type: 'datetime',
                        labels: {
                            step: 4,
                            formatter: function () {
                                return new Date(this.value).toLocaleDateString();
                            }
                        }
                    },
                    plotOptions: {
                        series: {
                            events: {
                                legendItemClick: function () {
                                    var visibility = this.visible ? 'visible' : 'hidden';
                                    if (visibility == 'hidden') {
                                        for (var i = 0; i < chs.length; i++) {
                                            wchartInstance.series[i].hide();
                                        }
                                    }
                                    return true;
                                }
                            }
                        }
                    },
                    yAxis: {
                        title: {
                            text: '数值'
                        },
                        plotLines: [{
                            value: 0,
                            width: 1,
                            color: '#808080'
                        }]
                    },
                    tooltip: {
                        formatter: function () {
                            return '<b>' + this.series.name + '：</b>' + this.y + '<br/> <b>时间：</b>' + new Date(this.x).toLocaleString();
                        }

                    },
                    legend: {
                        align: 'center',
                        verticalAlign: 'top',
                        borderWidth: 0
                    },
                    series: eval(s)
                });
            }
        };
        function cellstyle(value, row, index) {
            if (lvalue != 0) {
                if (gx == 1) {
                    if (index == "0") {
                        if (value < lvalue)
                            return 'background-color:#ffee00;color:red;';
                        else if (value >= lvalue && value < hvalue)
                            return 'background-color:#ffee00;color:green;';
                        else
                            return 'background-color:#ffee00;color:yellow;';
                    }
                }
                else if (gx == 2) {                    
                    if (index == "1") {
                        if (value < lvalue)
                            return 'background-color:#ffee00;color:red;';
                        else if (value >= lvalue && value < hvalue)
                            return 'background-color:#ffee00;color:green;';
                        else
                            return 'background-color:#ffee00;color:yellow;';
                    }
                }
                else if (gx == 3) {
                    if (index == "2") {
                        if (value < lvalue)
                            return 'background-color:#ffee00;color:red;';
                        else if (value >= lvalue && value < hvalue)
                            return 'background-color:#ffee00;color:green;';
                        else
                            return 'background-color:#ffee00;color:yellow;';
                    }
                }
                else if (gx == 4) {
                    if (index == "3") {
                        if (value < lvalue)
                            return 'background-color:#ffee00;color:red;';
                        else if (value >= lvalue && value < hvalue)
                            return 'background-color:#ffee00;color:green;';
                        else
                            return 'background-color:#ffee00;color:yellow;';
                    }
                }
                else if (gx == 5) {
                    if (index == "4") {
                        if (value < lvalue)
                            return 'background-color:#ffee00;color:red;';
                        else if (value >= lvalue && value < hvalue)
                            return 'background-color:#ffee00;color:green;';
                        else
                            return 'background-color:#ffee00;color:yellow;';
                    }
                }

            }

        }
        function showxc() {
                     
            year = new Date().getFullYear();
            var curr_time = new Date();
            var tc_time = new Date(curr_time.getTime() + 24 * 60 * 60 * 1000);
            var strDate = curr_time.getFullYear() + "-";
            strDate += curr_time.getMonth() + 1 + "-";
            strDate += curr_time.getDate();
            var strDateend = tc_time.getFullYear() + "-";
            strDateend += tc_time.getMonth() + 1 + "-";
            strDateend += tc_time.getDate();
            $("#StartTime").datebox("setValue", strDate);
            $("#EndTime").datebox("setValue", strDateend);
            $('#tone').datagrid({
                title: '墒情实时信息', //表格标题                
                sortName: 'datetime', //排序字段
                idField: 'ID', //标识字段,主键
                iconCls: '', //标题左边的图标
                width: 700, //宽度
                height: $("#my0").height(),
                nowrap: false, //是否换行，True 就会把数据显示在一行里
                striped: true, //True 奇偶行使用不同背景色
                collapsible: false, //可折叠
                sortOrder: 'desc', //排序类型
                remoteSort: true, //定义是否从服务器给数据排序
                fitColumns: true,
                singleSelect: false,
                rowStyler: function(index,row){
                    if (gx != "") {
                        if(index+1!=gx)
                        return 'background-color:gray;';
                    }
                },
                method: 'post',
                toolbar: "#tab_toolbarsone",
                columns: [[
                    { title: '土壤深度', field: 'cs', width: 120 },
                    { title: '土质', field: 'tz', width: 80 },
                    { title: '土壤温度', field: 'wd', width: 60 },
                    { title: '土壤湿度', field: 'sd', width: 60 },
                    {
                        title: '重量含水量', field: 'zl', width: 60
                    },
                    {
                        title: '相对含水量', field: 'xd', width: 60, styler: cellstyle
                    },
                    { title: '萎蔫系数', field: 'dl', width: 60 },
                    {
                        title: '监测时间', field: 'datetime', width: 100, formatter: function (value, row, index) {
                            if (value != "") {

                                if (value.indexOf("-") != -1)
                                    value = value.replace(/-/g, "/")
                                return new Date(value).pattern("yyyy年M月d日");
                            }
                        }
                    }
                ]
                ],
                onLoadSuccess: function (data) {                   
                    //生成预警
                    var rem = "";
                    rem = areas + "农田土壤墒情监测点土壤含水量监测结果分析：";
                    var zl;
                    var xd;
                    $.each(data.rows, function (k, v) {
                        zl = (parseFloat(v["土壤湿度1"]) / parseFloat(v["chn0"])).toFixed(2);
                        xd = (zl / parseFloat(v["chn1"])).toFixed(2);
                        re += k + 1 + "," + v["devname"] + "采样点0－10CM土壤绝对含水量平均为" + zl + "相对含水量平均为" + xd;
                        zl = (parseFloat(v["土壤湿度2"]) / parseFloat(v["chn0"])).toFixed(2);
                        xd = (zl / parseFloat(v["chn1"])).toFixed(2);
                        re += "10－30CM土壤绝对含水量平均为" + zl + "相对含水量平均为" + xd;
                        zl = (parseFloat(v["土壤湿度3"]) / parseFloat(v["chn0"])).toFixed(2);
                        xd = (zl / parseFloat(v["chn1"])).toFixed(2);
                        re += "30－50CM土壤绝对含水量平均为" + zl + "相对含水量平均为" + xd;
                        zl = (parseFloat(v["土壤湿度4"]) / parseFloat(v["chn0"])).toFixed(2);
                        xd = (zl / parseFloat(v["chn1"])).toFixed(2);
                        re += "50－80CM土壤绝对含水量平均为" + zl + "相对含水量平均为" + xd;
                        zl = (parseFloat(v["土壤湿度5"]) / parseFloat(v["chn0"])).toFixed(2);
                        xd = (zl / parseFloat(v["chn1"])).toFixed(2);
                        re += "80－100CM土壤绝对含水量平均为" + zl + "相对含水量平均为" + xd + ";";
                        //if (lvalue != 0) {
                        //    if (gx == 1) {
                        //        if (k == "0") {
                        //            if (value < lvalue)
                        //                return 'background-color:#ffee00;color:red;';
                        //            else if (value >= lvalue && value < hvalue)
                        //                return 'background-color:#ffee00;color:green;';
                        //            else
                        //                return 'background-color:#ffee00;color:yellow;';
                        //        }
                        //    }
                        //    else if (gx == 2) {
                        //        if (k == "1") {
                        //            if (value < lvalue)
                        //                return 'background-color:#ffee00;color:red;';
                        //            else if (value >= lvalue && value < hvalue)
                        //                return 'background-color:#ffee00;color:green;';
                        //            else
                        //                return 'background-color:#ffee00;color:yellow;';
                        //        }
                        //    }
                        //    else if (gx == 3) {
                        //        if (k == "2") {
                        //            if (value < lvalue)
                        //                return 'background-color:#ffee00;color:red;';
                        //            else if (value >= lvalue && value < hvalue)
                        //                return 'background-color:#ffee00;color:green;';
                        //            else
                        //                return 'background-color:#ffee00;color:yellow;';
                        //        }
                        //    }
                        //    else if (gx == 4) {
                        //        if (k == "3") {
                        //            if (value < lvalue)
                        //                return 'background-color:#ffee00;color:red;';
                        //            else if (value >= lvalue && value < hvalue)
                        //                return 'background-color:#ffee00;color:green;';
                        //            else
                        //                return 'background-color:#ffee00;color:yellow;';
                        //        }
                        //    }
                        //    else if (gx == 5) {
                        //        if (k == "4") {
                        //            if (value < lvalue)
                        //                return 'background-color:#ffee00;color:red;';
                        //            else if (value >= lvalue && value < hvalue)
                        //                return 'background-color:#ffee00;color:green;';
                        //            else
                        //                return 'background-color:#ffee00;color:yellow;';
                        //        }
                        //    }

                        //}

                    });
                    rem = rem + re;
                   
                    $("#yjfx").val(rem);
                },
                pagination: false, //是否开启分页                
                rownumbers: true
            });
            InitDLL();
            Highcharts.setOptions({
                lang: {
                    contextButtonTitle: "图表导出菜单",
                    decimalPoint: ".",
                    downloadJPEG: "下载JPEG图片",
                    downloadPDF: "下载PDF文件",
                    downloadPNG: "下载PNG文件",
                    downloadSVG: "下载SVG文件",
                    drillUpText: "返回 {series.name}",
                    loading: "加载中",
                    months: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
                    noData: "没有数据",
                    numericSymbols: ["千", "兆", "G", "T", "P", "E"],
                    printChart: "打印图表",
                    resetZoom: "恢复缩放",
                    resetZoomTitle: "恢复图表",
                    shortMonths: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
                    thousandsSep: ",",
                    weekdays: ["星期一", "星期二", "星期三", "星期三", "星期四", "星期五", "星期六", "星期天"]
                }
            });

            $("#yjfx").panel({
                href: '../html/alarm.html',
                title: '墒情预警信息',
                tools: [{ iconCls: 'icon-phone', handler: function () { sendAlarm('墒情预警'); } }],
                onLoad: function () {
                    InitSendUser();                    
                    $("#btnyj").click(function () {
                        sendAlarm('墒情预警');
                    });                    
                }
            });
            
            InitGird();

        }
        function InitDLL() {            
            $('#zw').combobox({
                url: '../plantinfo/GetPlant.ashx?action=ddllist',
                valueField: 'mpid',
                textField: 'pname',
                panelHeight: 'auto',
                width: 150,
                editable: false,
                onLoadSuccess: function () {
                    var data = $('#zw').combobox('getData');
                    if (data.length > 0)
                        $("#zw").combobox('select', data[0].caid);
                },
                onSelect: function (newValue, oldValue) {
                    if (newValue != null)
                        $('#sz').combobox({
                            url: '../zuowu/GetZW.ashx?action=ddllistsz&zwid=' + newValue.mpid,
                            valueField: 'grid',
                            textField: 'gname',
                            panelHeight: 'auto',
                            width: 150,
                            editable: false,
                            onSelect: function (newValue, oldValue) {                               
                                var sz = $('#sz').combobox('getValue');
                                //取得相关生长参数
                                $.ajax({
                                    type: "post",
                                    dataType: "json",
                                    url: "../zuowu/GetZW.ashx?action=queryszs&grid=" +sz,
                                    success: function aa(data) {
                                        if (data != null) {
                                            gx = data[0].gx;
                                            gpic = data[0].gpic;
                                            $('#szpic').attr("src",".."+gpic);
                                            var gid = mytz[gx].split("-")[0];
                                            $.ajax({
                                                type: "post",
                                                dataType: "json",
                                                url: "../zuowu/GetZW.ashx?action=queryrs&gid=" + gid + "&sz=" + sz,
                                                success: function aa(data) {
                                                    if (data != null) {
                                                        lvalue = data[0].lvalue;
                                                        hvalue = data[0].hvalue;                                                       
                                                        $('#tone').datagrid({
                                                            title: '土壤墒情(标准' + lvalue + ',' + hvalue + ')',
                                                        });
                                                        $('#tone').datagrid('loadData', gdate);
                                                    }
                                                }
                                            });
                                        }
                                    }

                                });
                               
                            }
                        });

                },
                onLoadSuccess: function () {
                    var data = $('#sz').combobox('getData');
                    if (data.length > 0)
                        $("#sz").combobox('select', data[0].caid);
                }
            });
        }

        function Initonegrid(i) {
            if (getdata1.rows.length > 0) {
                curindex = i;
                gdate = "";
                var onedata = [];
                var zl = (parseFloat(getdata1.rows[i].土壤湿度1) / parseFloat(myrz[0])).toFixed(2);
                var xd = (zl / parseFloat(mycs[0])).toFixed(2);
                onedata.push({ "cs": "第一层（0－10CM）","tz":mytz[0].split("-")[1], "wd": getdata1.rows[i].土壤温度1, "sd": getdata1.rows[i].土壤湿度1, "zl": zl, "xd": xd, "dl": mywn[0], "datetime": getdata1.rows[i].datetime });
                zl = (parseFloat(getdata1.rows[i].土壤湿度2) / parseFloat(myrz[1])).toFixed(2);
                xd = (zl / parseFloat(mycs[1])).toFixed(2);
                onedata.push({ "cs": "第二层（10－30CM）", "tz": mytz[1].split("-")[1], "wd": getdata1.rows[i].土壤温度2, "sd": getdata1.rows[i].土壤湿度2, "zl": zl, "xd": xd, "dl": mywn[1], "datetime": getdata1.rows[i].datetime });
                zl = (parseFloat(getdata1.rows[i].土壤湿度3) / parseFloat(myrz[2])).toFixed(2);
                xd = (zl / parseFloat(mycs[2])).toFixed(2);
                onedata.push({ "cs": "第三层（30－50CM）", "tz": mytz[2].split("-")[1], "wd": getdata1.rows[i].土壤温度3, "sd": getdata1.rows[i].土壤湿度3, "zl": zl, "xd": xd, "dl": mywn[2], "datetime": getdata1.rows[i].datetime });
                zl = (parseFloat(getdata1.rows[i].土壤湿度4) / parseFloat(myrz[3])).toFixed(2);
                xd = (zl / parseFloat(mycs[3])).toFixed(2);
                onedata.push({ "cs": "第四层（50－80CM）", "tz": mytz[3].split("-")[1], "wd": getdata1.rows[i].土壤温度4, "sd": getdata1.rows[i].土壤湿度4, "zl": zl, "xd": xd, "dl": mywn[3], "datetime": getdata1.rows[i].datetime });
                zl = (parseFloat(getdata1.rows[i].土壤湿度5) / parseFloat(myrz[4])).toFixed(2);
                xd = (zl / parseFloat(mycs[4])).toFixed(2);
                onedata.push({ "cs": "第五层（80－100CM）", "tz": mytz[4].split("-")[1], "wd": getdata1.rows[i].土壤温度5, "sd": getdata1.rows[i].土壤湿度5, "zl": zl, "xd": xd, "dl": mywn[4], "datetime": getdata1.rows[i].datetime });
                gdate = { "total": 5, "rows": onedata };
                $('#tone').datagrid('loadData', gdate);
            }
        }
        function createJB() {
            if (areas == "")
            {
                msgShow("提示", "请选择地区", "info");
                return;
            }
            var rows = $('#hzgrid').datagrid('getSelections');
            if (rows == null || rows.length == 0) {
                $.messager.alert("提示", "请选择要生成简报的行！", "info");
                return;
            }
            $('#jbdoc').hide();
            $('#jbdoc').attr("href", "#");
            $('#jbdata').show();
            $('#myjb').dialog({
                width: 800,
                height: 600,
                modal: true,
                title: areas + '简报',
                buttons: '#dlgjb-buttons',
                closed: false
            }).dialog('center');
            dtOpstart= $("#txtstart").datebox("getValue");
            dtOpend = $("#txtend").datebox("getValue");
            var re = "";
            if (dtOpstart != "")
                re += "从"+dtOpstart;
            if (dtOpend != "")
                re += "到" + dtOpend;
            $.ajax({
                type: "post",
                dataType: "json",
                url: "../devinfo/GetStatus.ashx?action=JBTSQ&StartTime=" + dtOpstart + "&EndTime=" + dtOpend+"&sebm="+sebm,
                success: function aa(data) {                   
                    re = areas + "平均气温是" + data[0].avgwd + "C,降雨量是" + data[0].sumyl + "。\r\n";
                    re += "农田土壤墒情监测点土壤含水量监测结果分析：";
                    var zl;
                    var xd;
                    $.each(hzdata.rows, function (k, v) {
                        zl = (parseFloat(v["土壤湿度1"]) / parseFloat(v["chn0"])).toFixed(2);
                        xd = (zl / parseFloat(v["chn1"])).toFixed(2);
                        re += k + 1 +","+ v["devname"] + "采样点0－10CM土壤绝对含水量平均为" + zl + "相对含水量平均为" + xd;
                        zl = (parseFloat(v["土壤湿度2"]) / parseFloat(v["chn0"])).toFixed(2);
                        xd = (zl / parseFloat(v["chn1"])).toFixed(2);
                        re += "10－30CM土壤绝对含水量平均为" + zl + "相对含水量平均为" + xd;
                        zl = (parseFloat(v["土壤湿度3"]) / parseFloat(v["chn0"])).toFixed(2);
                        xd = (zl / parseFloat(v["chn1"])).toFixed(2);
                        re += "30－50CM土壤绝对含水量平均为" + zl + "相对含水量平均为" + xd;
                        zl = (parseFloat(v["土壤湿度4"]) / parseFloat(v["chn0"])).toFixed(2);
                        xd = (zl / parseFloat(v["chn1"])).toFixed(2);
                        re += "50－80CM土壤绝对含水量平均为" + zl + "相对含水量平均为" + xd;
                        zl = (parseFloat(v["土壤湿度5"]) / parseFloat(v["chn0"])).toFixed(2);
                        xd = (zl / parseFloat(v["chn1"])).toFixed(2);
                        re += "80－100CM土壤绝对含水量平均为" + zl + "相对含水量平均为" + xd+";";

                    });
                    $("#jbdata").val(re);
                    $("#jbarea").val(areas);                    
                }
            });            
        }
        function outJB() {
            var f = $('#jbfm');           
            f.form('submit', {
                url: "../devinfo/GetJB.ashx?action=query",
                onSubmit: function () {
                    return $(this).form('validate');
                },
                success: function (result) {
                    if (result!="") {
                        $('#jbdoc').attr("href", result);
                        $('#jbdoc').show();
                        $('#jbdata').hide();
                    }                    
                }
            });
        }
    </script>
    <script id="tmpstations" type="text/html">
        {{each rows as value index}}
        <div class="stations">
            <div class="level1Div" onclick="showawsinfectInfo('{{value.DevID}}','{{value.chn0}}','{{value.chn1}}','{{value.chn2}}','{{value.XQHID}}')">
                <div class="levelsb">{{value.devname}}</div>
                <div class="leveltime">时间：{{value.mdatetime}} 已运行{{value.days}}天</div>
                <div class="levelbottom">
                    <div class="levelbtn">详细</div>
                </div>
            </div>
        </div>
        {{/each}} 
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <div id="mainDiv">
        <uc1:checkright runat="server" ID="checkright" />
        <uc1:ground runat="server" ID="ground" />
        <div id="contentDiv">
            <div class="mypt">
                <ul id="pt"></ul>
            </div>
            <div id="mycontent">
                <div id="tab" class="easyui-tabs">
                    <div title="GSI" style="padding: 5px;">

                        <div style="position: relative;">
                            <div id="mymap"></div>
                            <div id="Maptype" style="height: 87px; width: 130px; position: absolute; float: left; margin-left: 850px; top: 50px; z-index: 99; color: Black; border-bottom-left-radius: 5px; border-bottom-right-radius: 5px; border-top-left-radius: 5px; border-top-right-radius: 5px;">
                                <input id="CBstationname" onclick="ShowstationName('checkbox')" checked="checked" style="float: left; margin-left: 10px;"
                                    type="checkbox" />
                                <label onclick="ShowstationName('label')" style="height: 20px; width: 100px; float: left; text-align: left; font-size: 13px; font-family: 宋体; font-weight: bold; margin-top: 3px; cursor: pointer;">
                                    显示名称</label>
                            </div>
                        </div>

                    </div>
                    <div title="设备列表" style="overflow: auto; padding: 5px;">
                        <div id="mystations">
                        </div>
                    </div>
                    <div title="汇总" style="padding: 5px;">

                        <div id="hz">
                            <table id="hzgrid"></table>
                            <div id="hztoolbar">
                                <table cellpadding="0" cellspacing="0" style="width: 100%">
                                    <tr>
                                        <td style="padding-left: 2px">

                                            <div style="padding: 2px;">
                                                时间从:  
           <input id="txtstart" class="easyui-datebox" style="width: 100px" />
                                                到:  
           <input id="txtend" class="easyui-datebox" style="width: 100px" />
                                                <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="reloadgrid()">查找</a>
                                                <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="createJB()">简报</a>
                                            </div>
                                        </td>
                                    </tr>
                                </table>
                            </div>

                        </div>

                    </div>
                </div>
            </div>
            <div style="clear: both;"></div>
        </div>
        <uc1:copyright runat="server" ID="copyright" />


    </div>
    
    <div id="myjb" class="easyui-dialog" data-options="iconCls:'icon-save',modal:true,closed:true,buttons: '#dlgjb-buttons'" style="overflow: auto;">
 <form id="jbfm" method="post">
        <div class="easyui-panel" id="jb1" style="background: #eee; height:522px;">
           
            <textarea style="width:100%;height:100%;font-size:18px;line-height:24px;" name="jbdata" id="jbdata"></textarea>
                <input type="hidden" id="jbarea" name="jbarea" />               
               <a href="#" id="jbdoc" style="display:none;">下载简报</a>
            </div> 

 </form>
    </div>
    <div id="dlgjb-buttons">
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" onclick="outJB()">导出</a>
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="javascript:$('#myjb').dialog('close')">关闭</a>
    </div>
</asp:Content>

